<?php
ini_set('display_errors',1);
set_time_limit(0); 
include_once dirname(dirname(dirname(__FILE__))).'/mgtv_init.php';
include_once dirname(dirname(__FILE__)).'/init.php';

$db_r = nl_get_db(NL_DB_READ);
$db_r->open();

$db_w = nl_get_db(NL_DB_WRITE);
$db_w->open();


$sql="select nns_video_id,nns_video_index_id,count(*) as con
 from nns_mgtvbk_clip_task where nns_org_id='".SP_ORG_ID."' 
 group by nns_video_id,nns_video_index_id having con > 1 limit 100";
echo date('Y-m-d')." start...\n";
$list = nl_db_get_all($sql, $db_r);
if(count($list)>0){
	foreach($lst as $val){
		nl_db_get_col($sql, $db);
		$current_last_id_sql = "select nns_id from nns_mgtvbk_clip_task where nns_video_id='{$val['nns_video_id']}' and nns_video_index_id='{$val['nns_video_index_id']}' and  nns_org_id='".SP_ORG_ID."' order by nns_create_time desc limit 1";
		$current_last_id = nl_db_get_col($sql, $db_r);
		//$sql = "delete from nns_mgtvbk_clip_task where nns_video_id='{$val['nns_video_id']}' and nns_video_index_id='{$val['nns_video_index_id']}' and  nns_org_id='".SP_ORG_ID."' and nns_id!='{$current_last_id}'";
		nl_execute_by_db($sql, $db_w);		
	}
	echo date('Y-m-d')." working...\n";
}else{
	echo date('Y-m-d')." have no data!!!\n";
}
echo date('Y-m-d')." end...\n";
?>